﻿Option Explicit On
Option Strict On

Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports FRAMEWORK
Imports System.Drawing.Drawing2D
Public Class frm_ReceiptMoney
    Inherits asWins.Forms.BaseForm
    Dim Da As New FRAMEWORK.SQLDataAccess
    Dim cuscode As String
 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.grCustomer.Visible = False Then

            Me.grCustomer.Visible = True
            LoadCusAddress()
        Else
            Me.grCustomer.Visible = False
            cboCustCondition.SelectedIndex = -1
            txtCustSearch.Clear()
        End If
    End Sub
    Private Sub LoadCusAddress()
        Dim dt As DataTable

        Dim para(15) As SqlParameter

        para(0) = New SqlParameter("@ACTION", 7)
        para(1) = New SqlParameter("@Customer_Code", "")
        para(2) = New SqlParameter("@Employee_Code", "")
        para(3) = New SqlParameter("@Customer_Type", 0)
        para(4) = New SqlParameter("@Customer_Title", "")
        para(5) = New SqlParameter("@Customer_Name_1", "")
        para(6) = New SqlParameter("@Customer_Name_2", "")
        para(7) = New SqlParameter("@Customer_Dest", "")
        para(8) = New SqlParameter("@Customer_Status", 0)
        para(9) = New SqlParameter("@Create_User", FRAMEWORK.Framework.F_Username_Str)
        para(10) = New SqlParameter("@Create_Date", "")
        para(11) = New SqlParameter("@Update_User", FRAMEWORK.Framework.F_Username_Str)
        para(12) = New SqlParameter("@Update_Date", 0)
        para(13) = New SqlParameter("@Search", "")
        para(14) = New SqlParameter("@Con", 0)
        dt = Da.ExecuteDataset(CommandType.StoredProcedure, "sp_SYS_CUSTOMER", para).Tables(0)
        If dt.Rows.Count > 0 Then
            dgvCustAddress.DataSource = dt
        Else
            dgvCustAddress.DataSource = Nothing
        End If


    End Sub
    Private Sub dgvCustAddress_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvCustAddress.CellDoubleClick
        Me.grCustomer.Visible = False
        cuscode = dgvCustAddress.Rows(e.RowIndex).Cells(0).Value.ToString
        txtCust.Text = dgvCustAddress.Rows(e.RowIndex).Cells(1).Value.ToString
        'txtAddress.Text = dgvCustAddress.Rows(e.RowIndex).Cells(2).Value.ToString
        'txtContact.Text = dgvCustAddress.Rows(e.RowIndex).Cells(3).Value.ToString
        'txtTel.Text = dgvCustAddress.Rows(e.RowIndex).Cells(4).Value.ToString
        'cuscode = dgvCustAddress.Rows(e.RowIndex).Cells(0).Value.ToString
        'txtMobile.Text = dgvCustAddress.Rows(e.RowIndex).Cells(5).Value.ToString
        'cboCustCondition.SelectedIndex = -1
        txtCustSearch.Clear()
    End Sub

    Private Sub cmdJobSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdJobSearch.Click
        LoadAllreceipt()
        If Me.gbJobcode.Visible = False Then

            Me.gbJobcode.Visible = True

        Else
            Me.gbJobcode.Visible = False
        End If
    End Sub
    Private Sub LoadAllreceipt()
        cboCon.SelectedIndex = 0
        Dim dt As DataTable
        dgvJob.AutoGenerateColumns = False
        Dim para(3) As SqlParameter
        para(0) = New SqlParameter("@ACTION", 1)
        para(1) = New SqlParameter("@Receipt_Code", txtReceiptCode.Text)
        para(2) = New SqlParameter("@con", cboCon.SelectedIndex)
        para(3) = New SqlParameter("@search", txtSearch.Text)

        dt = Da.ExecuteDataset(CommandType.StoredProcedure, "sp_GetReCeipt", para).Tables(0)
        dgvJob.DataSource = dt
    End Sub

    Private Sub frm_ReceiptMoney_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Get_ALL_BankList()
    End Sub
    Private Sub frm_ReceiptMoney_Load(ByVal receipt As String)

    End Sub
  
    Private Sub dgvJob_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvJob.CellDoubleClick
        If e.RowIndex = -1 Then
            Exit Sub
        End If
        Me.gbJobcode.Visible = False
        txtReceiptCode.Text = dgvJob.Rows(e.RowIndex).Cells(0).Value.ToString
        LoadReceipt()
    End Sub
    Private Sub Get_ALL_BankList()
        Dim dt As DataTable

        Dim para(10) As SqlParameter

        para(0) = New SqlParameter("@ACTION", 3)
        para(1) = New SqlParameter("@BK_Code", "")
        para(2) = New SqlParameter("@BK_Number", "")
        para(3) = New SqlParameter("@BK_Owner", "")
        para(4) = New SqlParameter("@BK_Name", "")
        para(5) = New SqlParameter("@BK_Branch", "")
        para(6) = New SqlParameter("@BK_Type", "")
        para(7) = New SqlParameter("@BK_Remark", "")
        para(8) = New SqlParameter("@BK_Status", 0)
        para(9) = New SqlParameter("@Create_User", "")
        para(10) = New SqlParameter("@Update_User", "")

        dt = DA.ExecuteDataset(CommandType.StoredProcedure, "sp_SYS_BANKLIST", para).Tables(0)

        If dt.Rows.Count > 0 Then
            cboBanTransfer.DataSource = dt
            cboBanTransfer.DisplayMember = "FullName"
            cboBanTransfer.ValueMember = "BK_Code"
        
        End If


    End Sub
    Private Sub LoadReceipt()
        Dim dt As DataTable
        dgvJob.AutoGenerateColumns = False
        Dim para(3) As SqlParameter
        para(0) = New SqlParameter("@ACTION", 3)
        para(1) = New SqlParameter("@Receipt_Code", txtReceiptCode.Text)
        para(2) = New SqlParameter("@con", cboCon.SelectedIndex)
        para(3) = New SqlParameter("@search", txtSearch.Text)

        dt = Da.ExecuteDataset(CommandType.StoredProcedure, "sp_GetReCeipt", para).Tables(0)
        dgvJob.DataSource = dt
        If dt.Rows.Count > 0 Then
            GetDetail(dt)
            btnAdd.Enabled = False
        End If
    End Sub
    Private Sub GetDetail(ByVal dt As DataTable)
        Dim dr As DataRow
        For Each dr In dt.Rows
            cbotype.Text = dr!Receipt_Type.ToString()
            cuscode = dr!Receipt_Cust.ToString()
            txtCust.Text = dr!Customer_Name_1.ToString() ' ใส่ไว้ก่อน
            ' getCustName()
            cboCash.Text = dr!Receipt_Cash.ToString()
            txtCash.Text = dr!Receipt_CashRemark.ToString()
            txtCashAmount.Text = dr!Receipt_Cash_Amount.ToString()
            cboTransfer.Text = dr!Receipt_Transfer.ToString()
            txtTranferAmount.Text = dr!Receipt_Transfer_Amount.ToString()
            cboCheq1.Text = dr!Receipt_Cheq.ToString()
            'cboBankID.SelectedValue = dr!
            txtBarcode2.Text = dr!Receipt_CheqBK_Code.ToString()
            txtBranch.Text = dr!Receipt_Cheq_Branch.ToString()
            txtCheqAmount.Text = dr!Receipt_Cheq_Amount.ToString()
            dtCheq1.Value = CDate(dr!Receipt_Cheq_date)

            txtTotal1.Text = dr!Receipt_TotalAmount1.ToString()

            txtTotalAmount.Text = dr!Receipt_TotalAmount2.ToString()
        Next
    End Sub
End Class